package logic

import (
	"context"
	"shuqi-novel/models"

	"shuqi-novel/novelrpc/internal/svc"
	"shuqi-novel/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ArticleListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewArticleListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleListLogic {
	return &ArticleListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 列表
func (l *ArticleListLogic) ArticleList(in *novelrpc.ArticleListRequest) (*novelrpc.ArticleListResponse, error) {
	// todo: add your logic here and delete this line

	var article models.Article

	if err := article.FindArticle(models.DB, in.ArticleId); err != nil {
		return nil, err
	}

	return &novelrpc.ArticleListResponse{
		Name:   article.Name,
		Author: article.Author,
		Price:  float32(article.Price),
	}, nil
}
